package com.xyy.saas.payment.controller;

import com.alibaba.fastjson.JSON;
import com.xyy.saas.payment.cores.vo.ResultVO;

import com.xyy.saas.payment.pojo.vo.JdCreditBIllListReq;
import com.xyy.saas.payment.pojo.vo.JdCreditBIllListVo;
import com.xyy.saas.payment.pojo.vo.JdCreditBillRepayVo;
import com.xyy.saas.payment.pojo.vo.PageVo;
import com.xyy.saas.payment.service.JdCreditRepayService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @author liujf
 * 京东金融还款界面
 */
@Slf4j
@RestController
@RequestMapping("/jdCredit")
public class JdCreditRepayController {
    @Resource
    private JdCreditRepayService jdCreditRepayService;

    @PostMapping(value = "/bill/list")
    public ResultVO<PageVo<JdCreditBIllListVo>> billList(@RequestBody JdCreditBIllListReq req) {
        try {
            PageVo<JdCreditBIllListVo> pageVo = jdCreditRepayService.billList(req);
            return ResultVO.createSuccess(pageVo);
        } catch (Exception e) {
            log.error("JdCreditRepayController#billList error", e);
            return ResultVO.createError("查询列表失败");
        }
    }
    @PostMapping(value = "/bill/exportList")
    public void billExportList(@RequestBody JdCreditBIllListReq req, HttpServletResponse response) {
        try {
            log.info("jdCredit#export:{}", JSON.toJSONString(req));
            jdCreditRepayService.billExportList(req, response);
        } catch (Exception e) {
            log.error("jdCredit#export error", e);
        }
    }
    @PostMapping(value = "/bill/detail")
    public ResultVO<JdCreditBillRepayVo> billDetail(@RequestParam("payNo") String payNo) {
        try {
            if (StringUtils.isBlank(payNo)) {
                return ResultVO.createError("查询参数支付单号不为空");
            }
            JdCreditBillRepayVo repayVo = jdCreditRepayService.billDetail(payNo);
            return ResultVO.createSuccess(repayVo);
        } catch (Exception e) {
            log.error("JdCreditRepayController#billDetail error", e);
            return ResultVO.createError("查询还款计划失败");
        }
    }

}
